package org.jpass.dc.business.conpiler;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

public class CustomClassLoader extends ClassLoader {

	@Override
	protected Class<?> findClass(String name) throws ClassNotFoundException {
		byte [] data  =  loadClassData(name);
        return  defineClass(name, data,  0 , data.length);
	}
	
	public byte[] loadClassData(String dirPath) {
		FileInputStream fis = null;
		byte[] data = null;
		try {
			fis = new FileInputStream(new File(dirPath));
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			int ch = 0;
			while ((ch = fis.read()) != -1) {
				baos.write(ch);
			}
			data = baos.toByteArray();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return data;
	}
	
	

}
